#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

void tree (char * path, int depth)
{
	struct DIR * dir;
	struct dirent * entry;
	char buf[1024];
	int d, s;

	dir = opendir(path);
	if (!dir) return;
	
	s = strlen(path);
	strcpy(buf, path);
	buf[s] = '/';

	while (entry = readdir(dir))
	{
		if (strcmp(entry->d_name, ".") == 0) continue;
		if (strcmp(entry->d_name, "..") == 0) continue;

		strcpy(buf + s + 1, entry->d_name);
		buf[s + 1 + strlen(entry->d_name)] = 0;

		for (d = 0; d < depth + 1; ++d)
			printf("   ");
		printf("%s\n", entry->d_name);

		tree(buf, depth + 1);
	}
}

int main (int argc, char ** argv)
{
	if (argc != 2)
	{
		printf("Usage: %s <directory>", argv[0]);
		return 0;
	}
	printf("%s\n", argv[1]);
	tree(argv[1], 0);
}
